package com.example.widgetdemo618lw;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private TextView tvInfo;
    private EditText etInfo;
    private Button btnInfo,btnOpen,btnChange,btnGetCender;
    private ImageView imageView;
    private RadioGroup rg;
    private CheckBox cblan,cbzu,cbyou;
    private String strXingqu="";




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initViews();

    }

    private void initViews() {
        tvInfo=findViewById(R.id.textView);
        etInfo=findViewById(R.id.editText);
        btnInfo=findViewById(R.id.button);
        btnOpen=findViewById(R.id.button2);
        btnChange=findViewById(R.id.button3);
        imageView=findViewById(R.id.imageView);
        rg=findViewById(R.id.radiogroup);
        btnGetCender=findViewById(R.id.Button4);
        cblan=findViewById(R.id.checkBox4);
        cbzu=findViewById(R.id.checkBox3);
        cbyou=findViewById(R.id.checkBox2);


        cblan.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(b)
                    strXingqu+="-篮球-";
                else
                    strXingqu=strXingqu.replace("-篮球-","");
                tvInfo.setText(strXingqu);

            }
        });
        cbzu.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(b)
                    strXingqu+="-足球-";
                else
                    strXingqu=strXingqu.replace("-足球-","");
                tvInfo.setText(strXingqu);

            }
        });
        cbyou.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(b)
                    strXingqu+="-游泳-";
                else
                    strXingqu=strXingqu.replace("-游泳-","");
                tvInfo.setText(strXingqu);

            }
        });


        btnInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String string=etInfo.getText().toString();
                tvInfo.setText(string);

            }
        });


        btnOpen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(MainActivity.this,Main2Activity.class);

                startActivity(intent);
                finish();//关闭当前Activity
            }
        });

        btnChange.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                imageView.setImageResource(R.drawable.yys);
            }
        });

        /*btnGetCender.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });*/
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                switch(i)//第二个形参i就是被选中资源的id
                {
                    //女
                    case R.id.radioButton:
                        tvInfo.setText("女");
                        break;
                    case R.id.radioButton2:
                        //男
                        tvInfo.setText("男");
                        break;
                }
            }
        });









    }
}
